home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / File / Disks & Drivers < prev    next >
Encoding:
Text File  |  1999-03-04  |  2.9 KB  |  120 lines  |  [TEXT/ToyS]

  1. (*
  2. Watches the free space on volumes in an info window
  3.  
  4. Applet(StayOpen, NoDialog)
  5. *)
  6.  
  7. -- Preferences
  8. property kasPrefName : "Disks & Drivers V1.1"
  9. property kasColors : {15, 15 * 32, 15 * 1024}
  10. property kasFontName : "Monaco"
  11. property kasFontSize : 10
  12.  
  13. -- Globals
  14. global gasInfoWind -- Info window
  15. global gasInfoPos -- Position of info window
  16. global gasLastVolCnt -- Last volume count
  17.  
  18.  
  19. on run
  20.     pfLoad()
  21.     set gasLastVolCnt to 0
  22.     set gasInfoWind to display info titled kasPrefName ¬
  23.         located at gasInfoPos
  24. end run
  25.  
  26.  
  27. on idle
  28.     display info gasInfoWind message "••• SCANNING •••" at line gasLastVolCnt
  29.     
  30.     set volCnt to 0
  31.     set volIdx to 1
  32.     
  33.     repeat while true
  34.         try
  35.             set vInfo to the volume info of volume index volIdx
  36.         on error
  37.             exit repeat
  38.         end try
  39.         
  40.         set volCnt to volIdx
  41.         set infoPos to DisplayLine(vInfo, volIdx)
  42.         set volIdx to volIdx + 1
  43.     end repeat
  44.     
  45.     -- Invalidate removed volume?
  46.     if (volCnt < gasLastVolCnt) then
  47.         repeat with n from volCnt to (gasLastVolCnt - 1)
  48.             display info gasInfoWind message "…" at line n
  49.         end repeat
  50.     end if
  51.     
  52.     set gasLastVolCnt to volCnt
  53.     
  54.     -- Save Screen Location of info window if changed
  55.     if (infoPos is not gasInfoPos) then
  56.         set gasInfoPos to infoPos
  57.         pfSave()
  58.     end if
  59.     
  60.     return 60
  61. end idle
  62.  
  63.  
  64. on DisplayLine(info, lineNum)
  65.     set freeBytes to ((vol block size of info) * (vol free blocks of info))
  66.     set pctFull to recompose ((vol free blocks of info) / (vol total blocks of info)) with percentage
  67.     
  68.     set myCol to item 1 of kasColors
  69.     if (vol kind of info is AFP volume) then set myCol to item 2 of kasColors
  70.     if (vol read only of info is true) then set myCol to item 3 of kasColors
  71.     
  72.     if (pctFull < 10) then set myCol to myCol + (15 * 1024)
  73.     
  74.     if (vol removable of info) then
  75.         set myLine to "*"
  76.     else
  77.         set myLine to " "
  78.     end if
  79.     
  80.     if (vol kind of info is HFS plus volume) then
  81.         set myLine to myLine & "+ "
  82.     else
  83.         set myLine to myLine & "  "
  84.     end if
  85.     
  86.     set myLine to myLine & (recompose (vol ref of info) padded to 3)
  87.     set myLine to myLine & (recompose (vol name of info) padded to 28)
  88.     set myLine to myLine & (recompose pctFull padded to -8)
  89.     set myLine to myLine & (recompose freeBytes padded to -10 with kilomegs)
  90.     set myLine to myLine & (recompose (vol driver ref of info) padded to -4)
  91.     
  92.     set myLine to myLine & (recompose ((vol block size of info) * (vol total blocks of info)) padded to -10 with kilomegs)
  93.     set myLine to myLine & "  " & (vol driver name of info)
  94.     
  95.     return screen location of ¬
  96.         (display info gasInfoWind ¬
  97.             message myLine ¬
  98.             at line lineNum ¬
  99.             using font kasFontName ¬
  100.             using size kasFontSize ¬
  101.             using color myCol ¬
  102.             with a change of style and static state)
  103. end DisplayLine
  104.  
  105.  
  106. on pfLoad()
  107.     try
  108.         set ourPrefs to load preference named kasPrefName
  109.     on error
  110.         set ourPrefs to {pfWLoc:{40, 64}}
  111.     end try
  112.     
  113.     set gasInfoPos to pfWLoc of ourPrefs
  114. end pfLoad
  115.  
  116.  
  117. on pfSave()
  118.     save preference {pfWLoc:gasInfoPos} named kasPrefName
  119. end pfSave
  120.